package polinomios;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Polinomio {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		fromStringToPolinomio("");

	}
	
	public static int[] fromStringToPolinomio(String polinomio) {
		
		Pattern pat = null;
		Matcher mat = null;
		
		String aux = "";
		polinomio = "100+3x^2+5x-89x^88-x^6-89+45-1-x+x";
		
		String regex = "(\\+|-|^)[1-9][0-9]*(\\+|-|$)";
		
		pat = Pattern.compile(regex);
		aux = polinomio;
		mat = pat.matcher(aux);
		
		while(mat.find()){
			if(mat.end()-1 <= 0)
				break;
			System.out.println("Encontre: "+mat.group());
			System.out.println("Empieza en: "+mat.start());
			System.out.println("termina en: "+mat.end());
			aux = aux.substring(mat.end()-1);
			System.out.println("Nuevo pol: "+aux);
			mat = pat.matcher(aux);
			System.out.println("---------");
		}
		
		regex = "(\\+|-|^)x(\\+|-|$)";
		
		pat = Pattern.compile(regex);
		aux = polinomio;
		mat = pat.matcher(aux);
		
		while(mat.find()){
			if(mat.end()-1 <= 0)
				break;
			System.out.println("Encontre: "+mat.group());
			System.out.println("Empieza en: "+mat.start());
			System.out.println("termina en: "+mat.end());
			aux = aux.substring(mat.end()-1);
			System.out.println("Nuevo pol: "+aux);
			mat = pat.matcher(aux);
			System.out.println("---------");
		}
		
		regex = "(\\+|-|^)[1-9][0-9]*x(\\+|-|$)";
		
		pat = Pattern.compile(regex);
		aux = polinomio;
		mat = pat.matcher(aux);
		
		while(mat.find()){
			if(mat.end()-1 <= 0)
				break;
			System.out.println("Encontre: "+mat.group());
			System.out.println("Empieza en: "+mat.start());
			System.out.println("termina en: "+mat.end());
			aux = aux.substring(mat.end()-1);
			System.out.println("Nuevo pol: "+aux);
			mat = pat.matcher(aux);
			System.out.println("---------");
		}
		
		regex = "(\\+|-|^)x\\^[1-9][0-9]*(\\+|-|$)";
		
		pat = Pattern.compile(regex);
		aux = polinomio;
		mat = pat.matcher(aux);
		
		while(mat.find()){
			if(mat.end()-1 <= 0)
				break;
			System.out.println("Encontre: "+mat.group());
			System.out.println("Empieza en: "+mat.start());
			System.out.println("termina en: "+mat.end());
			aux = aux.substring(mat.end()-1);
			System.out.println("Nuevo pol: "+aux);
			mat = pat.matcher(aux);
			System.out.println("---------");
		}
		
		regex = "(\\+|-|^)[1-9][0-9]*x\\^[1-9][0-9]*(\\+|-|$)";
		
		pat = Pattern.compile(regex);
		aux = polinomio;
		mat = pat.matcher(aux);
		
		while(mat.find()){
			if(mat.end()-1 <= 0)
				break;
			System.out.println("Encontre: "+mat.group());
			System.out.println("Empieza en: "+mat.start());
			System.out.println("termina en: "+mat.end());
			aux = aux.substring(mat.end()-1);
			System.out.println("Nuevo pol: "+aux);
			mat = pat.matcher(aux);
			System.out.println("---------");
		}
		
		return null;
	}

}
